package com.sskj.wallet.ui.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.wallet.R;
import com.sskj.wallet.R2;
import com.sskj.wallet.presenter.AddAddressPresenter;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/06/26
 */
@Route(path = RConfig.WALLET_ACTIVITY_ADD_ADDRESS)
public class AddAddressActivity extends BaseActivity<AddAddressPresenter> {
    @Autowired
    String addressType;
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.et_address)
    EditText etAddress;
    @BindView(R2.id.iv_saoma)
    ImageView ivSaoma;
    @BindView(R2.id.et_note)
    EditText etNote;
    @BindView(R2.id.btn_withdraw)
    Button btnWithdraw;

    @Override
    public int getLayoutId() {
        return R.layout.wallet_activity_add_address;
    }

    @Override
    public AddAddressPresenter getPresenter() {
        return new AddAddressPresenter();
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
        tvTitle.setText(App.INSTANCE.getString(R.string.wallet_addAddressActivity1));
    }

    @Override
    public void initData() {
        //添加提币地址
        ClickUtil.click(300, btnWithdraw, () -> {
            if (isEmpty(etAddress)) {
                toastHint(etAddress);
                return;
            }
            if (isEmpty(etNote)) {
                toastHint(etNote);
                return;
            }
            mPresenter.addAddress(getText(etAddress), "", getText(etNote), addressType);
        });
        //扫码添加提币地址
        ClickUtil.click(300, ivSaoma, () -> {
            ARouter.getInstance().build(RConfig.QUICK_MARK).navigation(this, Constans.QUCIK_BACK);
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == Constans.QUCIK_BACK) {
            String scan_result = data.getStringExtra("scan_result");
            etAddress.setText(TextUtils.isEmpty(scan_result) ? "" : scan_result);
        }
    }
}